import Vue from "vue";

//分页参数
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 20,
  currentPage: 1
};

// 和网络交互相关的参数
let params = {
  id:'',
  platform:'',
  siteCode:'',
};

let status={
  modalDelete:{
    isShow: false,
    isLoading: false,
    title:'用户',
    email:{
      id:'',
      userName:'',
      userEmail:'',
    },
  },
  modalAdd:{
    isShow: false,
    isLoading: false,
  },
  ruleValidate: {
    platform: [
      { required: true,type: 'integer', min: 1, message: '支付平台不能为空', trigger: 'change' }
    ],
    name: [
      { required: true, message: '支付名称不能为空', trigger: 'blur' }
    ],
    mode: [
      { required: true, message: '模式不能为空', trigger: 'blur' }
    ],
    account: [
      { required: true, message: '登录账户不能为空', trigger: 'blur' }
    ],
    fixedPoundage: [
      { required: true, type:'number', message: '固定手续费不能为空', trigger: 'blur' }
    ],
    poundageRate: [
      { required: true,type:'number', message: '手续费比例不能为空', trigger: 'blur' }
    ]
  },
}



// 页面的数据源
let data = {
  paymentAccountList: [],
  disable:false,
  paymentAccount:{
    id:'',
    platform:0,
    name:'',
    account:'',
    mode:'',
    site:[],
    stateStatus:true,
    merchantId:'',
    publicKey:'',
    privateKey:'',
    clientId:'',
    clientSecret:'',
    apiKey:'',
    state:'',
    note:'',
    fixedPoundage:0,
    poundageRate:0,
    minPaymentAmount:0,
    maxPaymentAmount:9999
  },

};

const tableRowActionEdit = function (self) {
  return {
    title: '操作',
    key: 'action',
    width: 150,
    align:'center',
    render: (h, params) => {
      return (
        <div>
          < i-button type="error" size="small"  style="margin-right:10px" onClick={() => {self.editAction(params.index)}}>编辑</i-button>
        </div>
      );

    }
  }
};

let table = function (self) {
  return [
    {
      title: '序号',
      type: 'index',
      width: 80,
      align: 'center',
    },
    {
      title: '支付平台',
      align: 'center',
      key: 'platform',
      width: 200,
      render:(h,params)=>{
        let value=params.row.platform;
        let cDict = self.$store.getters.dictionaries['payTypeDict'];
        let name = "";
        if (cDict) {
          let dict = cDict.filter(function (item) {
            return item.value == value
          })
          if (dict.length > 0) {
            name = dict[0].name;
          }
        }
        return h('div',name);
      }
    },
    {
      title: '支付名称',
      align: 'center',
      key: 'name',
      minWidth: 250,
    },
    {
      title: '状态',
      key: 'state',
      width: 200,
      align: 'center',
      render: (h, params) => {
        let state = params.row.state==1;
        return (
          <div>
            <tag color={state?'green':'red'}>{state?'启动':'停用'}</tag>
          </div>
        );
      }

    },
    {
      title: '创建时间',
      align: 'center',
      width: 180,
      key: 'createtime',
      render:(h,params)=>{
        return h('div',Vue.prototype.$tiyBJTime(params.row.createtime));
    }
    },
    tableRowActionEdit(self)
  ];
}

export  default  {
  tPage: page,
  tParam: params,
  tData: data,
  tStatus: status,
  tTable:table,
};
